<?php

namespace app\common\model;

class MachineCost extends Base
{
    protected $deleteTime = 'delete_time';

    /**
     * @param int $specs_id
     * @param string $machine_id
     * @return MachineCost|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMachineCostBySpecsIdAndMachineID(int $specs_id = 0, string $machine_id = "")
    {
        return $this
            ->where('machine_id', $machine_id)
            ->where('specs_id', $specs_id)
            ->find();
    }

    /**
     * 查询正常的机器商品配置
     * @param string $machine_id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMachineCostByMachineIdInfo(string $machine_id = ""): array
    {
        return $this->where('machine_id', $machine_id)
            ->where('status', 1)
            ->select()
            ->toArray();
    }

    /**
     * @param array $ids
     * @param string $machine_id
     * @param string $field
     * @param stirng|array $with
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMachineCostByIds(array $ids = [],string $machine_id = '', string $field = '*',$with = null)
    {
        return $this->field($field)
            ->where('machine_id',$machine_id)
            ->whereIn('specs_id', $ids)
            ->with($with)
            ->select()
            ->toArray();
    }
}